<?php

declare(strict_types=1);

namespace app\admin\controller\choujiang;

use think\facade\Request;
use app\common\service\ChoujiangGoodsconfig as S;
use app\common\model\ChoujiangGoodsconfig as M;
use app\common\model\AdminAdmin as UM;

class Goodsconfig extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // -----------------------------------------   特殊类型物品  添加到数据库 写死id  -----------------------------------------

    //INSERT INTO `gmpre`.`gm_items` (`itemid`, `itemname`) VALUES (1919199, '平台币');
    //INSERT INTO `gmpre`.`gm_items` (`itemid`, `itemname`) VALUES (1919198, '盲盒金币');



    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(M::getList());
        }
        return $this->fetch('index',['ItemLs' => UM::getItemLsSelect()]);
    }

    // 添加
    public function add()
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goAdd(Request::post()));
        }
        return $this->fetch('add',['ItemLs' => UM::getItemLsSelect()]);
    }

    // 编辑
    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goEdit(Request::post(), $id));
        }
        return $this->fetch('edit', ['model' => M::find($id),'ItemLs' => UM::getItemLsSelect()]);
    }

    // 状态
    public function status($id)
    {
        return $this->getJson(S::goStatus(Request::post('status'), $id));
    }

    // 删除
    public function remove($id)
    {
        return $this->getJson(S::goRemove($id));
    }

    // 批量删除
    public function batchRemove()
    {
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
    }

    // 回收站
    public function recycle()
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goRecycle());
        }
        return $this->fetch();
    }
}
